<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ include file="/public/header.jsp"%>
<html>
	<head>
		<title>项目合同管理</title>
	</head>
	<script type="text/javascript">
	$(function(){
		$("#searchValue").keypress(function(e) { 
	    	// 回车键事件 
	     	if(e.which == 13) { 
	     		 doSearch();
	       	} 
	   	}); 
		$("#searchValueTwo").keypress(function(e) { 
	    	// 回车键事件 
	     	if(e.which == 13) { 
	     		 doSearch();
	       	} 
	   	}); 
		$("#dept_id").combotree({
			url:'<%=contextPath %>/springMVC/group/listDepartment',
			method:'POST',
			animate:true,
			lines:true,
			onChange:function(){
				doSearch();
			}
		});
		$("#table").datagrid({
			title:"项目合同管理",
			iconCls:'icon-edit',
			loadMsg:'正在加载数据，请稍后......',
			url:'<%=contextPath %>/springMVC/xm/listPageXmContract',
			rownumbers:true,
			fitColumns:true,
			nowrap:false,
			idField:'id',
			frozenColumns:[[
				//{field:'ck',checkbox:true},		
			    {title:'主键',field:'id',hidden:true},
			    {title:'项目id',field:'xm_id',hidden:true}
			]],
			columns:[[
				{title:'所属部门',field:'dept_name',width:200,align:'center'},
				{title:'合同编号',field:'contract_code',width:100,align:'center'},
				{title:'项目名称',field:'xm_code',width:200,align:'center'},
				{title:'项目名称',field:'xm_name',width:200,align:'center'},
				{title:'经办人id',field:'creator_id',hidden:true},
				{title:'经办人',field:'creator',width:100,align:'center'},
				{title:'审批状态',field:'status',hidden:true},
				{title:'审批状态',field:'status_name',width:100,align:'center'},
				{title:'详情操作',field:'more',width:100,align:'center',formatter:function(value,rowData,rowIndex){
					var str="";
					if(rowData.status == 0  || rowData.status == 2){
						str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEditContract(1,'"+rowData.id+"');\"/> &nbsp;&nbsp;";
						str+="<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi(this,'"+rowData.id+"');\"/> &nbsp;&nbsp;";
						str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-no' title='删除' onclick=\"javascript:deleteRows('"+rowData.id+"');\"/>&nbsp;&nbsp;";
						return str;
					}
					if(rowData.status>0){
						str+="<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审核查看' onclick=\"javascript:viewFlowView('"+encodeURIComponent("<%=FlowUtility.XM_CONTRACT_SHENPI%>")+"','"+rowData.id+"');\"/>&nbsp;&nbsp;";
					}
					if(rowData.status>0){
                    	str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='详情' onclick=\"javascript:addOrEditContract(2,'"+rowData.id+"');\"/>";
					}
                    return str;
				}}
			]],
			
			toolbar:"#tb",
			pageSize:10,
			pageList : [10,50,100],  
			pagination:true,
			onLoadSuccess:function(rtJson){
				if(rtJson.rtState== '1')
				{
					$.messager.alert('提示',rtJson.rtMsrg);
				}
			}
		});
	});
		//--end 
	function shenpi(obj,id){
    	//flowBusinessUrl获取审批业务记录的URL(可以是个组合参数字符串),moduleFlow获取工作流程的流程名称
	      var flowBusinessUrl="<%=contextPath %>/springViews/xm/addOrEditContract.jsp?id="+id+"&isShow=1";
	      var param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.XM_CONTRACT_SHENPI%>")+"&businessId="+id;
	      $(obj).hide();
	      $.ajax({
						type:'POST',
						url:'<%=contextPath %>/springMVC/workFlow/toShenpi',
						dataType:"JSON",
						data:param,
						success:function(rtJson){
							if (rtJson.rtState == '0'){
								openDialogResize(rtJson.rtData.url,1000,800);
							}else{
								warningInfo(rtJson.rtMsrg);
							}
							$(obj).show();
						}
					});
       
    } 
	function addOrEditContract(type,id){
		if(type==0){
			openDialogResize('<%=contextPath %>/springViews/xm/addOrEditContract.jsp?callback=rtCallBack',1000, 800);
		}else if(type==1){
			openDialogResize('<%=contextPath %>/springViews/xm/addOrEditContract.jsp?callback=rtCallBack&id='+id,1000, 800);
		}else{
			openDialogResize('<%=contextPath %>/springViews/xm/addOrEditContract.jsp?isShow=1&callback=rtCallBack&id='+id,1000, 800);
		}
	}
	function rtCallBack(){
		$('#table').datagrid('reload');
	}
	
	function deleteRows(){
		var rows=$('#table').datagrid('getSelections');
		var deleteVar="";
		if(rows.length==0)
		{
			$.messager.alert('提示','选中要删除的记录');  
			return ;
		}
		for(var i=0;i<rows.length;i++)
		{
			if(i==(rows.length-1))
			{
				deleteVar+=rows[i].id;
			}else
			{
				deleteVar+=rows[i].id+",";
			}
		}
		$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
			if(msg){
				$.ajax({
					type:'POST',
					url:"<%=contextPath %>/springMVC/xm/deleteContract",
					data:"ids="+deleteVar,
					dataType:"json",
					success:function(rtJson){
						if(rtJson.rtState == '0'){
							table_reload(rows.length);
						}
						else{
							$.messager.alert('提示：',rtJson.rtMsrg);
						}
					}
				});
			}
		});
	}
	
	function doSearch()
	{
		var searchValueTwo = $('#searchValueTwo').val();
		var searchValue = $('#searchValue').val();
		var dept_id = $('#dept_id').combotree('getValue');
		$('#table').datagrid('load',{
			searchValueTwo:searchValueTwo,
			dept_id:dept_id,
			searchValue:searchValue
		});
	}
	</script>
<body  style="height: 97%">
	<div id="table"  data-options="toolbar:'#tb',fit:true" ></div>  
	  
    <div id="tb" style="padding:3px;height:auto">
		<div style="float:left;">
			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addOrEditContract(0);">添加合同</a>
		</div>
		<div align="right">
			所属部门：<input  id="dept_id" name="dept_id" class="easyui-combotree">  
			项目编号/名称：<input id="searchValue" name="searchValue" style="width:150px" title="项目编号/名称" placeholder="项目编号/名称 "  />&nbsp;&nbsp; 
			合同编号：<input id="searchValueTwo" name="searchValueTwo" style="width:150px" title="合同编号" placeholder="合同编号" />&nbsp;&nbsp; 
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
		</div>
	</div>
	
</body>
</html>